package com.wanxing.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.zhny.wxginger.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class MyAdapter extends SimpleAdapter {

	private ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
	private Context context;
	private LayoutInflater listContainer;

	public MyAdapter(Context context, ArrayList<HashMap<String, String>> data,
			int resource, String[] from, int[] to) {
		super(context, data, resource, from, to);
		this.listContainer = LayoutInflater.from(context); // ������ͼ����������������
		this.context = context;
		list = data;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return super.getCount();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return super.getItem(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return super.getItemId(position);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		viewHolder holder;
		if (convertView == null) {
			holder = new viewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.data_show_item, null);
			holder.img = (ImageView) convertView
					.findViewById(R.id.data_imageView1);
			holder.name = (TextView) convertView.findViewById(R.id.data_name);
			holder.vaule = (TextView) convertView.findViewById(R.id.data_vaule);
			holder.unit = (TextView) convertView.findViewById(R.id.data_unit);
			convertView.setTag(holder);
		} else {
			holder = (viewHolder) convertView.getTag();
		}

		if (position == 0) {
			holder.img.setImageResource(R.drawable.actionbar_add_icon);
			holder.name.setText(list.get(0).get("Dname"));
			holder.vaule.setText(list.get(0).get("Ddate"));
			holder.unit.setText(list.get(0).get("Dunit"));
		} else if (position == 1) {
			holder.img.setImageResource(R.drawable.ic_launcher);
			holder.name.setText(list.get(1).get("Dname"));
			holder.vaule.setText(list.get(1).get("Ddate"));
			holder.unit.setText(list.get(1).get("Dunit"));
		} else if (position == 2) {
			holder.img.setImageResource(R.drawable.ic_launcher);
			holder.name.setText(list.get(2).get("Dname"));
			holder.vaule.setText(list.get(2).get("Ddate"));
			holder.unit.setText(list.get(2).get("Dunit"));
		} else if (position == 3) {
			holder.img.setImageResource(R.drawable.ic_launcher);
			holder.name.setText(list.get(3).get("Dname"));
			holder.vaule.setText(list.get(3).get("Ddate"));
			holder.unit.setText(list.get(3).get("Dunit"));
		} else if (position == 4) {
			holder.img.setImageResource(R.drawable.ic_launcher);
			holder.name.setText(list.get(4).get("Dname"));
			holder.vaule.setText(list.get(4).get("Ddate"));
			holder.unit.setText(list.get(4).get("Dunit"));
		} else if (position == 5) {
			holder.img.setImageResource(R.drawable.ic_launcher);
			holder.name.setText(list.get(5).get("Dname"));
			holder.vaule.setText(list.get(5).get("Ddate"));
			holder.unit.setText(list.get(5).get("Dunit"));

		} else if (position == 6) {
			holder.img.setImageResource(R.drawable.ic_launcher);
			holder.name.setText(list.get(6).get("Dname"));
			holder.vaule.setText(list.get(6).get("Ddate"));
			holder.unit.setText(list.get(6).get("Dunit"));

		} else if (position == 7) {
			holder.img.setImageResource(R.drawable.ic_launcher);
			holder.name.setText(list.get(7).get("Dname"));
			holder.vaule.setText(list.get(7).get("Ddate"));
			holder.unit.setText(list.get(7).get("Dunit"));
		} else if (position == 8) {
			holder.img.setImageResource(R.drawable.ic_launcher);
			holder.name.setText(list.get(8).get("Dname"));
			holder.vaule.setText(list.get(8).get("Ddate"));
			holder.unit.setText(list.get(8).get("Dunit"));
		}
		return convertView;
	}

	public class viewHolder {
		ImageView img;
		TextView name;
		TextView vaule;
		TextView unit;
	}
}
